package sixth.group.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import sixth.group.domain.Customer;
import sixth.group.service.WwzCustomerService;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

@Controller
@RequestMapping(value="/customer")
public class WwzCustomerController {

    @Autowired
    private WwzCustomerService wwzCustomerService;

    @RequestMapping({"/balancerecharge"})
    public void balanceRecharge(Integer money, HttpSession httpSession, HttpServletResponse response) throws IOException {
        PrintWriter out = response.getWriter();
        Customer customer=(Customer) httpSession.getAttribute("Customer");
        Integer cid=customer.getCid();
        wwzCustomerService.BalanceRecharge(cid, money);
        Integer qian=customer.getCbalance();
        qian+=money;
        customer.setCbalance(qian);
        httpSession.setAttribute("Customer",customer);
        out.println("<script type='text/javascript'>alert('Success!');window.location.href='../home.jsp'</script>");
    }
}